package com.yycx.module.bus.provider.controller;

import com.yycx.module.bus.provider.service.BusFinanceDetailsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.yycx.common.mybatis.model.*;

import java.util.HashMap;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RestController;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.BusFinance;
import com.yycx.module.bus.provider.service.BusFinanceService;
import org.springframework.web.multipart.MultipartFile;


/**
 * 部门对账表控制器
 *
 * @author flyme
 * @date 2021-01-05
 */
@RestController
@RequestMapping("/bus/finance/")
public class BusFinanceController extends BaseController<BusFinanceService, BusFinance> {

    @Autowired
    private BusFinanceDetailsService financeDetailsService;

    @ApiOperation(value = "部门对账表-分页列表", notes = "部门对账表分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "部门对账表-列表", notes = "部门对账表列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "部门对账表-添加", notes = "添加部门对账表")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "部门对账表-更新", notes = "更新部门对账表")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "部门对账表-删除", notes = "删除部门对账表")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "部门对账表-详情", notes = "部门对账表详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "部门对账表-导入数据", notes = "部门对账表-导入数据")
    @PostMapping(value = "importData")
    public ResultBody importData(@RequestParam(required = false) Map params, @RequestParam("file") MultipartFile file) {
        ResultBody resultBody = bizService.importData(file, params);
        return resultBody;
    }

    @ApiOperation(value = "部门对账表-导出数据", notes = "部门对账表-导出数据")
    @PostMapping(value = "exportData")
    public void exportData(HttpServletRequest request, HttpServletResponse response, @RequestParam Long financeId) {
        bizService.exportData(response, financeId);
    }


    @ApiOperation(value = "部门对账表-初始化数据", notes = "部门对账表-初始化数据")
    @PostMapping(value = "syncData")
    public ResultBody syncData(@RequestParam Long financeId) {
        //financeDetailsService.initBusFinanceDetails(financeId);
        Thread t = new Thread(() -> {
            bizService.initData(financeId);
        });
        t.start();
        return ResultBody.ok();
    }

}
